class HashTable {
    constructor() {
        this.storage = [];
        this.count = 0;
        this.limit = 8;
    }

    hashFunc(str, max) {
        let hashCode = 0;
        for(let i = 0; i < str.length; i++) {
            hashCode = 31  * hashCode + str[i].charCodeAt();
        }
        hashCode = hashCode % max;
        return hashCode;
    }

    put(key, value) {
        const index = this.hashFunc(key, this.limit);
        let bucket = this.storage[index];
        if(bucket === undefined) {
            bucket = [];
            this.storage[index] = bucket;
        }
        let overide = false;
        for(let i = 0; i < bucket.length; i++) {
            let tuple = bucket[i]
            if(tuple[0] === key) {
                tuple[1] = value;
                overide = true;
            }
        }
        if(!overide) {
            bucket.push(key, value);
            this.count++
        }
    }
}
const hashTable = new HashTable();
hashTable.put("name", "leilei")
console.log(hashTable);